<?php

class VipsetController extends MyClass_Action {
	protected $controller;
	protected $action;
	protected $_user;
	
	public function init() {
		
		$this->commonAction();	
	
	}
	
	public function serviceAction(){
		try {
			$sql="SELECT * FROM `vip_item`";
			$result=$this->_dbAdapter ->fetchAssoc ( $sql );
			$sql="SELECT * FROM `vip_item_set_v`";
			$res=$this->_dbAdapter ->fetchAll ( $sql );
			//print_r($result);echo '<br />';print_r($res);exit;
			$this->view->result=$result;
			$this->view->res=$res;
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function vipsetsaveAction() {
		try {
			
			if (! $this->isPost ()) {
					throw new Exception ( '参数错误！' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);
			$isok=0;
			foreach($p['itemid'] as $key=>$value){
				for($i=0;$i<3;$i++){
					if(isset($p['see'][$value][$i])){
						$see=1;
					}else{
						$see=0;
					}
					if(isset($p['use'][$value][$i])){
						$use=1;
					}else{
						$use=0;
					}
					$data=array(
						'itemid'=>$value,
						'canlook'=>$see,
						'canuse'=>$use,
					);
					//print_r($data);exit;
					$res=$this->_dbAdapter->update('vip_item_set',$data,"itemid='".$value."' and viptype=".$i."");
					if($res){
						$isok=1;
					}
				}
			}
			
			if($isok){
				$this->feedback ( '更新成功', '注意', '/'.$this->controller.'/service', 'warning' );
			}else{	
				throw new Exception ( '更新失败或没有更改任何内容 ！' );
			}
			//print_r($p);exit;
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), '注意', 'javascript:window.history.back();', 'warning' );
		}
	}
	


	 //以下内容保持不变
	public function noRouteAction() {
		$this->_redirect ( '/' );
	}
	
	public function __call($method, $args) {
		if ('Action' == substr ( $method, - 6 )) {
			$url = '/' . $this->controller . '/index';
			return $this->_redirect ( $url );
		}
		throw new Exception ( 'Invalid method' );
	}}

